﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Snowflake.Core;

namespace SimpleSqlSugarTemplate
{
	public static class TestSnowFlake
	{
		private static IdWorker worker;
		static TestSnowFlake()
		{
			var workerId = 1; // 通常从配置文件或环境变量获取
			var dataCenterId = 1; // 通常从配置文件或环境变量获取
			worker = new IdWorker(workerId, dataCenterId);
		}
		public static void Test()
		{
			#region
			for (int i=0;i<100;i++)
			{
				long id = worker.NextId();
				Console.WriteLine(id);
			}
			#endregion
			List<long> ids = new List<long>(10000);
			List<Task> tasks = new List<Task>();
			for (int i = 0; i < 10; i++) 
			{
				tasks.Add(Task.Run(() => {

					for (int i = 0; i < 100; i++)
					{
						long id = worker.NextId();
						ids.Add(id);
					}
				}));
			}

			Task.WaitAll(tasks.ToArray());


			var data=ids.GroupBy(id=>id).Select(id=>new {id=id,count=id.Count()}).Where(id=>id.count>1).ToArray();

			Console.WriteLine(data.Count());
		}
	}
}
